package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleSecvice;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "床位管理相关接口")
public class AlertRuleConrtoller extends BaseController {


    @Autowired
    private AlertRuleSecvice alertRuleSecvice;

    @RequestMapping("/create")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleSecvice.create(alertRuleDto);
        return ResponseResult.success();
    }

    @GetMapping("/get-page")
    public ResponseResult<PageResponse<AlertRuleVo>>getPage(Integer pageNum,
                                                            Integer pageSize,
                                                            String alertRuleName,
                                                            String productKey,
                                                            String functionName) {
        PageResponse<AlertRuleVo> pageResponse = alertRuleSecvice.getPage(pageNum, pageSize, alertRuleName, productKey, functionName);
        return ResponseResult.success(pageResponse);
    }


    @GetMapping("/read/{id}")
    public ResponseResult<AlertRuleVo> readBed(@PathVariable("id") Long id) {
        AlertRuleVo alertRuleVo = alertRuleSecvice.read(id);
        return ResponseResult.success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    public ResponseResult updateBed(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleSecvice.update(alertRuleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delBed(@PathVariable("id") Long id) {
        alertRuleSecvice.delete(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        alertRuleSecvice.updateStatus(id, status);
        return ResponseResult.success();
    }

}
